﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Authorization;
using Abp.Domain.Repositories;
using Abp.Runtime.Caching;
using GaoTang.Base.Dto;
using GaoTang.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;


namespace GaoTang.Base
{
    [AbpAllowAnonymous]
    public class PersonAppService : AsyncCrudAppService<Person, PersonDto, int, PagedResultRequestDto, CreatePersonDto, PersonDto>, IPersonAppService
    {
        private readonly ICacheManager _cacheManager;

        public PersonAppService(IRepository<Person, int> repository, ICacheManager cacheManager) : base(repository)
        {
            _cacheManager = cacheManager;

            this.InitRedisCache();
        }

        public string InitRedisCache()
        {
           var result = _cacheManager.GetCache("test").Get("test001", () => { return "Hello world GaoTang"; });

            return result;
        }

        //public override async Task<PersonDto> Create(CreatePersonDto input)
        //{
        //    var person = ObjectMapper.Map<Person>(input);

        //    await this.Repository.InsertAsync(person);

        //    return base.MapToEntityDto(person);
        //}

        //protected override PersonDto MapToEntityDto(Person user)
        //{
        //    var roles = _roleManager.Roles.Where(r => user.Roles.Any(ur => ur.RoleId == r.Id)).Select(r => r.NormalizedName);
        //    var userDto = base.MapToEntityDto(user);
        //    userDto.RoleNames = roles.ToArray();
        //    return userDto;
        //}
    }
}
